$(function() {
	layer.config({
	    extend: ['skin/fpxskin/style.css']  //加载弹出层皮肤
	});
	
	//列表数据鼠标悬浮事件
	$(".px-grid-row").mouseover(function() {
		$(this).addClass("activerow").find(".px-button-group").show();
	}).mouseout(function() {
		$(this).removeClass("activerow").find(".px-button-group").hide();
	});
	
	//高级查询
	$(".high-search").on("click", function() {
		$(".high-query").slideToggle(); 
	});
	
	//修改
	$(".px-grid").on("click", ".edit-btn", function() {
		$("#myModal").modal("show");
	});
	
	//删除操作
	$(".deleteBtn").on("click", function() {
		var ischecked = $(this).closest(".px-grid-row-content").find("input[type='checkbox']").is(":checked");
		if(!ischecked){
			layer.msg('请选择要操作的数据', {
		   		icon: 6,
		   		offset: 'rb',
		   		icon: 1,
		   		skin: "skindangercss"
		   	});
		   	return;
		}
		layer.open({
	        type: 1,
	        title: "提示",
	        skin: "skindangercss",
	        shadeClose: true, //点击遮罩关闭
	        //area: ['300px', '200px'],
	        content: '您确定要删除吗？',
	        btn: ['确定', '取消']
			  ,yes: function(index, layero){
			   	layer.msg('操作成功', {
			   		offset: 'rb',
			   		icon: 2, //成功
			   		skin: "skinsuccesscss"
			   	});
			   	layer.close(index);  //回调关闭
			  },btn2: function(){ 
			  }
	    });
	});
	
	//删除全部操作
	$(".deleteAllBtn").on("click", function() {
		if($(".px-grid").find("input[type='checkbox']:checked").length<1){
			layer.msg('请选择要操作的数据', {
		   		offset: 'rb',
		   		icon: 1, 
		   		skin: "skindangercss"
		   	});
		   	return;
		}
		layer.open({
	        type: 1,
	        title: "提示",
	        skin: "skindangercss",
	        shadeClose: true, //点击遮罩关闭
	        //area: ['300px', '200px'],
	        content: '您确定要删除吗？',
	        btn: ['确定', '取消']
			  ,yes: function(index, layero){
			   	layer.msg('操作成功', {
			   		skin: "skinsuccesscss",
			   		offset: 'rb',
			   		icon: 2 //成功
			   	});
			   	layer.close(index);  //回调关闭
			  },btn2: function(){ 
			  }
	    });
	});
	
	//绑定icheck事件
	$('input').iCheck({
	    checkboxClass: 'icheckbox_flat-blue',
	    radioClass: 'iradio_flat-blue'
	});
	
	//全选,反选
	$(".selectAll").on("ifClicked", function() {
		var $this = $(this);
		var $chks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]');
		if($this.is(":checked")){  //之前没有选中
			for(var i=0; i<$chks.length; i++) {
				$($chks[i]).iCheck('uncheck');
			}
		}else{
			for(var i=0; i<$chks.length; i++) {
				$($chks[i]).iCheck('check');
			}
		}
	});
	
	//部分选，取消全选
	$(".selectOne").on("ifClicked", function() {
		var $this = $(this);
		var $selectAll = $(".selectAll");
		var allChks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]').length;  
		var chks = $this.closest(".px-grid").find('.px-grid-row input[type="checkbox"]:checked').length;
		if($this.is(":checked")) { //当前是选中
			$selectAll.iCheck("uncheck");	
		}else{
			if(allChks == (chks+1)){
				$selectAll.iCheck("check");
			}else{
				$selectAll.iCheck("uncheck");
			}
		}
	});
});
